package dtos

import (
	"strconv"

	"github.com/beego/beego/v2/core/validation"
)

type RefreshTokenParams struct {
	UserId    int64
	UserIdStr string `json:"user_id"`
	Token     string `json:"token"`
}

func (rtp *RefreshTokenParams) Valid(v *validation.Validation) {
	// 验证UserId是否合法
	var err error
	rtp.UserId, err = strconv.ParseInt(rtp.UserIdStr, 10, 64)

	if err != nil {
		_ = v.SetError("UserId", "用户编号不合法")
		return
	}

	// 验证 Token 是否合法
	if rtp.Token == "" {
		_ = v.SetError("token", "token 不合法")
		return
	}

	return
}
